home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!sun2!ua302aa
- From: ua302aa@sun2.lrz-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: To malloc (new) or not to malloc? When is the question.
- Date: 10 Jan 1996 12:08:25 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4d0a7p$aco@sparcserver.lrz-muenchen.de>
- References: <4ctvk3$ort@maverick.tad.eds.com> <pwolf-0901960912510001@pwolf-mac.qualcomm.com>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- pwolf@qualcomm.com (Paul I. Wolf ) writes:
-
- >In article <4ctvk3$ort@maverick.tad.eds.com>, fignet05.darrins@eds.com
- >(Darrin Smith) wrote:
- >[snip]
- >> Why is it that you can do something like the following:
- >> char *x;
- >> x="Some really long string with no particular meaning";
- >First example is incorrect. You may be thinking of declaring with initializing:
- > char* x = "Some really long string with no particular meaning";
-
- There is nothing "incorrect" about the code posted by Mr. Smith, afaik.
- You may assign a pointer to char to a variable of that type without
- any special measures, and there is no need to do that in the initialization
- of that variable.
-
- >Same thing works for second example if you initialize with constants:
- > struct st1{char one[10];
- > char two[20];
- > char three[10];
- > }* sptr= {0};
-
- >The point is that memory allocatiion during initialization is required if
- >you want the pointer to "automatically" point to memory which can be used.
-
- This is _not_ the point in the first example. A pointer to char was
- declared. So, space for that pointer has been reserved. The pointer
- does not point to a specific memorz location. The assignment changes
- the value of the variable "x". No problem there.
-
- >In your first example, the "x=" is NOT valid syntax for a sequence of
- >characters.
-
- It is a valid assignment of a pointer to char.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-